//
//  HNSH_BusinessCircleRecordCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/9/26.
//

#import "HNSH_BusinessCircleRecordCell.h"

@interface HNSH_BusinessCircleRecordCell ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;
/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;
/* statusLabel */
@property (nonatomic, strong) UILabel *statusLabel;

/* xfLabel */
@property (nonatomic, strong) UILabel *xfLabel;
/* zsLabel */
@property (nonatomic, strong) UILabel *zsLabel;
/* reasonLabel */
@property (nonatomic, strong) UILabel *reasonLabel;
/* timeLabel */
@property (nonatomic, strong) UILabel *timeLabel;

@end

@implementation HNSH_BusinessCircleRecordCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor appBGColor];
        [self configView];
    }
    return self;
}

- (void)setModel:(HNSH_BusinessCircleRecordModel *)model {
    _model = model;

    self.titleLabel.text = model.shop_name;
    
    self.xfLabel.text = [NSString stringWithFormat:@"消费金额：%.2f",[model.amount doubleValue]];
    self.zsLabel.text = [NSString stringWithFormat:@"打赏比例：%.2f%%",[model.reward_ratio doubleValue] * 100];
    self.reasonLabel.text = [NSString stringWithFormat:@"拒绝原因：%@",model.verify_content];
    self.timeLabel.text = [NSString stringWithFormat:@"申请时间：%@",model.create_time];
    
    if (model.status == 120 || model.status == 130) {
        self.statusLabel.text = @"已拒绝";
        self.statusLabel.textColor = [UIColor appGreenColor];
        self.reasonLabel.hidden = NO;
        [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.reasonLabel.mas_bottom).offset(4);
            make.left.mas_equalTo(16);
            make.height.mas_equalTo(17);
            make.bottom.mas_equalTo(-16);
        }];
    } else {
        self.reasonLabel.hidden = YES;
        [self.timeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.zsLabel.mas_bottom).offset(4);
            make.left.mas_equalTo(16);
            make.height.mas_equalTo(17);
            make.bottom.mas_equalTo(-16);
        }];
        
        if (model.status == 10 || model.status == 20) {
            self.statusLabel.text = @"审核中";
            self.statusLabel.textColor = [UIColor appGreenColor];
        } if (model.status == 100) {
            self.statusLabel.text = @"已通过";
            self.statusLabel.textColor = [UIColor appGrayLabelColor];
        }
    }
}

- (void)configView {
    [self.contentView addSubview:self.bgView];
    
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.statusLabel];
    
    [self.bgView addSubview:self.xfLabel];
    [self.bgView addSubview:self.zsLabel];
    [self.bgView addSubview:self.reasonLabel];
    [self.bgView addSubview:self.timeLabel];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.bottom.mas_equalTo(0);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(16);
        make.height.mas_equalTo(22);
    }];
    
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(22);
    }];
    
    [self.xfLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
        make.left.mas_equalTo(16);
        make.height.mas_equalTo(17);
    }];
    
    [self.zsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.xfLabel.mas_bottom).offset(4);
        make.left.mas_equalTo(16);
        make.height.mas_equalTo(17);
    }];
    
    [self.reasonLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.zsLabel.mas_bottom).offset(4);
        make.left.mas_equalTo(16);
        make.height.mas_equalTo(17);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.reasonLabel.mas_bottom).offset(4);
        make.left.mas_equalTo(16);
        make.height.mas_equalTo(17);
        make.bottom.mas_equalTo(-16);
    }];
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = [UIColor appWhiteLabelColor];
        _bgView.layer.cornerRadius = 8.0f;
        _bgView.layer.masksToBounds = YES;
    }
    return _bgView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.textColor = [UIColor appBlackLabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:16];
    }
    return _titleLabel;
}

- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = [[UILabel alloc]init];
        _statusLabel.textColor = [UIColor appGreenColor];
        _statusLabel.font = [UIFont systemFontOfSize:14];
    }
    return _statusLabel;
}

- (UILabel *)xfLabel {
    if (!_xfLabel) {
        _xfLabel = [[UILabel alloc]init];
        _xfLabel.textColor = [UIColor appGray666LabelColor];
        _xfLabel.font = [UIFont systemFontOfSize:12];
    }
    return _xfLabel;
}

- (UILabel *)zsLabel {
    if (!_zsLabel) {
        _zsLabel = [[UILabel alloc]init];
        _zsLabel.textColor = [UIColor appGray666LabelColor];
        _zsLabel.font = [UIFont systemFontOfSize:12];
    }
    return _zsLabel;
}

- (UILabel *)reasonLabel {
    if (!_reasonLabel) {
        _reasonLabel = [[UILabel alloc]init];
        _reasonLabel.textColor = [UIColor appOrangeLabelColor];
        _reasonLabel.font = [UIFont systemFontOfSize:12];
        _reasonLabel.hidden = YES;
    }
    return _reasonLabel;
}

- (UILabel *)timeLabel {
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.textColor = [UIColor appGray666LabelColor];
        _timeLabel.font = [UIFont systemFontOfSize:12];
    }
    return _timeLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
